<?php
session_start();
$openid=NULL;
if (isset($_GET['op'])){
    $openid=$_GET['op'];
    $_SESSION['openid']=$openid;
}
if (isset($_SESSION['openid'])){
    $openid=$_SESSION['openid'];
}
if (empty($openid)){
    exit;
}


include_once("./c/config.php");
$userInfo=array();
$mysqli = new mysqli($dbhost, $dbuser, $dbpwd, $dbName);
if (!$mysqli->set_charset("utf8")) {printf("Error loading character set utf8: %s\n", $mysqli->error);}
$hasU=2;

if (isset($_SESSION['hasU'])){
    $hasU=$_SESSION['hasU'];
}else{
    $query=$mysqli->query("select id from u3 where openid='".$openid."' limit 0, 1");
    if($query->num_rows>0){
        $hasU=1;
        $_SESSION['hasU']=1;
    }else{
        $query=$mysqli->query("select id from u4 where openid='".$openid."' limit 0, 1");
        if($query->num_rows>0){
            $hasU=1;
            $_SESSION['hasU']=1;
        }
    }
}

$query=$mysqli->query("SELECT count(id) as count FROM `ci3` where openid='".$openid."' ");
$getCount=$query->fetch_assoc();
//$count=$getCount['count']+1;

$query=$mysqli->query("SELECT count(id) as count FROM `ci4` where openid='".$openid."' ");
$getCountB=$query->fetch_assoc();
$count=$getCount['count']+$getCountB['count']+1;

$_SESSION['cishu']=$count;

$url=$urlB='http://tu-10030004.file.myqcloud.com/si/';
$url=$urlB='./';
$_SESSION['skey']=rand(1,99999999);
$mysqli->close();
?><!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1">
<title>古诗文大会</title>
<style>
html,body{font-size:16px;width:100%;font-size:12px;color:#fff;font-family:Microsoft YaHei, Gotham, "Helvetica Neue", Helvetica, Arial, sans-serif;}
body, div{position:relative;padding:0px;margin:0px auto;max-width:750px;}
.weui-dialog{position:fixed;z-index:5000;width:80%;max-width:300px;top:50%;left:50%;-webkit-transform:translate(-50%,-50%);transform:translate(-50%,-50%);background-color:#FFF;text-align:center;border-radius:3px;overflow:hidden}.weui-dialog__hd{padding:1.3em 1.6em .5em}.weui-dialog__title{font-weight:400;font-size:18px}.weui-dialog__bd{padding:0 1.6em .8em;min-height:40px;font-size:15px;line-height:1.3;word-wrap:break-word;word-break:break-all;color:#999}.weui-dialog__bd:first-child{padding:1.2em 20px .1em;color:#353535}.weui-dialog__ft{position:relative;line-height:48px;font-size:18px;display:-webkit-box;display:-webkit-flex;display:flex}.weui-dialog__ft:after{content:" ";position:absolute;left:0;top:0;right:0;height:1px;border-top:1px solid #D5D5D6;color:#D5D5D6;-webkit-transform-origin:0 0;transform-origin:0 0;-webkit-transform:scaleY(.5);transform:scaleY(.5)}.weui-dialog__btn{display:block;-webkit-box-flex:1;-webkit-flex:1;flex:1;color:#3CC51F;text-decoration:none;-webkit-tap-highlight-color:transparent;position:relative}.weui-dialog__btn:active{background-color:#EEE}.weui-dialog__btn:after{content:" ";position:absolute;left:0;top:0;width:1px;bottom:0;border-left:1px solid #D5D5D6;color:#D5D5D6;-webkit-transform-origin:0 0;transform-origin:0 0;-webkit-transform:scaleX(.5);transform:scaleX(.5)}.weui-dialog__btn:first-child:after{display:none}.weui-dialog__btn_default{color:#353535}.weui-dialog__btn_primary{color:#0BB20C}@media screen and (min-width:1024px){.weui-dialog{width:35%}}.weui-mask{position:fixed;z-index:1000;top:0;right:0;left:0;bottom:0;background:rgba(0,0,0,.6)}.weui-mask_transparent{position:fixed;z-index:1000;top:0;right:0;left:0;bottom:0}
-webkit-touch-callout:none;
-webkit-user-select:none;
html{-ms-touch-action:none;}
*{-webkit-overflow-scrolling:touch;}
.fixfixed {position:absolute;}
div,img{-webkit-tap-highlight-color:rgba(0,0,0,0);}
*{-webkit-text-size-adjust: none;}
.simg{position:absolute;display:block;}
a{text-decoration:none;}
.txt{position:absolute;text-indent:6px;font-size:12px;z-index:2;}
.txt::-webkit-input-placeholder {color:#b4b4b4;text-align:left;}
.container{position:relative;width:100%;height:auto;overflow:hidden;}
.p1, .qu, .p3, .p2, .p4{position:absolute;width:100%;height:100%;display:none;}
.p1{background:#f5f3e9;} 
input{position:absolute;display:block;text-indent:10px;-webkit-appearance:none;background:none;padding:0;outline-style:none;border:none;color:#000;}
select{position:absolute;display:block;background:transparent;border:0px;text-indent:8px;font-size:12px;-webkit-appearance:none;}

.a100{position:absolute;display:block;width:100%;left:0;}
 
.t-rule, .t-zhuyi, .ti{position:absolute;width:100%;z-index:99;top:0px;left:0px;display:none;}
.t-end, .t-wan{position:absolute;width:100%;z-index:9999;top:0px;left:0px;display:none;}
.p-b, .thebg{position:absolute;width:100%;top:0;left:0;} 
#iosDialog2{display:none;}
.p1-top{position:absolute;width:100%;display:block;top:0;left:0;}
.p1-t1{background:transparent url('<?php echo $urlB; ?>img3/p1-t1.png') no-repeat;background-size:cover;}
.p1-t2{position:absolute;width:100%;display:block;bottom:2%;left:0;}
.p4-down{position:absolute;width:100%;}
.p4-shi, .p4-fen, .p4-miao{position:absolute;font-size:16px;color:#333333;font-weight:700;text-align:right;}
.t-bg, .t-bg2{position:absolute;width:100%;height:100%;background-color:#000000;opacity:.9;top:0px;left:0px;}
.t-bg{display:none;z-index:9;}
.hide{display:none;}

.p3-t3, .p4-t3{position:absolute;overflow-y:scroll;}
.p3-t3 img, .p4-t3 img{display:block;width:100%;}

::-webkit-scrollbar{
  width: 5px;
  height: 5px;
}
::-webkit-scrollbar-thumb{
  border-radius: 1em;
  background-color:#a1a0a0;
}
::-webkit-scrollbar-track{
  border-radius: 1em;
  background-color: #cbcbcb;
}
.p2-s1{position:absolute;background:transparent url('<?php echo $urlB; ?>img3/school.png') no-repeat;background-size:cover;}
.p2-s1-2{position:absolute;width:100%;height:100%;left:0;top:0;}
</style>
</head>
<body>
<div class="container">
  <div class="p1 page">
     <img class="p1x p-b" src="<?php echo $urlB; ?>img3/index.jpg">
     
     <img class="p1-t2 simg " src="<?php echo $urlB; ?>img3/p1-t2.png">
     <div class="thebg">
         <div class="p1-t1 a100">
            <div class="p1-bao simg"></div>
            <div class="p1-rule simg"></div>
         </div>
		 
     </div>
  </div> 

  
  
  <div class="p2">
      <img class="bg simg" src="<?php echo $urlB; ?>img3/b.jpg">
      <img class="p2-t1 a100" src="<?php echo $urlB; ?>img3/p2-t1.png">
      
	   
      <div class="thebg">
         <img class="p-b simg" src="<?php echo $urlB; ?>img3/p2.png?v=4">
         

         <input id="p2-name" class="txt" name="name"  type="text" value="" placeholder="请填写学生姓名"  />
		 <input id="p2-phone" class="txt" name="phone" type="number" value="" placeholder="请填写真实手机号码"  />
         <input id="p2-email" class="txt" name="email" type="email" value="" placeholder="请填写电子邮箱"  />
		 <input id="p2-hao" class="txt" name="hao" type="text" value="" placeholder="请填写本人的电子学生证"  />

         <select id="p2-nianji" name="nianji">
				<option value="">选择年级</option>
				<option value="3">三年级</option>
				<option value="4">四年级</option>
				<option value="5">五年级</option>
				<option value="6">六年级</option>
	     </select>
	     
	     <select id="p2-szqu" name="szxqu">
				<option value="">所在选区</option>
				<option value="上海选区">上海选区</option>
				<option value="南通分赛区">南通分赛区</option>
				<option value="其他">其他</option>
	     </select>
	     
	     <select id="p2-fxqu" name="fenxqu">
				<option value="">分会场</option>
				 
	     </select>
	     <div class="p2-s1">
             <img class="p2-s1-2" src="<?php echo $urlB; ?>img3/school2.png">
         </div>
         <input id="p2-school2" class="txt hide" name="school2" type="text" value="" placeholder="请填写学校"  />
         <select id="p2-school" name="school">
				<option value="">请选择所在学校</option>
	     </select>
	     
          
         <div class="p2-jin simg"></div>
      </div>
  
  </div>
  
  <div class="p3">
      <img class="bg simg" src="<?php echo $urlB; ?>img3/b.jpg">
      
      <div class="thebg">
         
         <img class="p3-t1 a100" src="<?php echo $urlB; ?>img3/p3-t1.png">
         
         <div class="p3-t3">
            <img src="<?php echo $urlB; ?>img3/p3-txt.png?v=4"><br />
         </div>
          <img class="p3-t2 simg" src="<?php echo $urlB; ?>img3/p3-t2.png">
      </div>
  </div>
  
  <div class="p4">
      <img class="bg simg" src="<?php echo $urlB; ?>img3/p4.jpg">
      <img class="p4-t1 a100" src="<?php echo $urlB; ?>img3/p4-t1.jpg">
      <div class="p4-t3">
            <img src="<?php echo $urlB; ?>img3/p4-txt.png"><br />
      </div>
  
     <img class="p4-b1 simg" src="<?php echo $urlB; ?>img3/p4-b1.png">
  </div>
 
   
  <div class="js_dialog" id="iosDialog2" style="opacity: 1;">
       <div class="weui-mask"></div>
       <div class="weui-dialog">
                <div class="weui-dialog__bd weui-msg"></div>
                <div class="weui-dialog__ft">
                    <a href="javascript:;" class="weui-dialog__btn weui-dialog__btn_primary weui-btn">知道了</a>
                </div>
        </div>
 </div>
  
</div>
<script src="http://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>
<script src="<?php echo $url; ?>/js/pxloader-images.min.js"></script>
<script src="<?php echo $url; ?>/js/jquery.countdown.min.js"></script>
<script src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>
<script>
var _hasU='<?php echo $hasU; ?>';
h= Math.max(document.documentElement.clientHeight, window.innerHeight || 0);
var sWidth = parseInt((window.innerWidth > 0) ? window.innerWidth : screen.width);
if(sWidth>750){sWidth=750;}
var _rate=(sWidth/750);
if(h<_rate*1206){
	h=_rate*1206;
}
var _img=['p1-top.jpg'];
var loader = new PxLoader();
for(var i=0; i<_img.length; i++){loader.addImage('<?php echo $urlB; ?>/img2/'+_img[i]);}
loader.start();
loader.addCompletionListener(function(e) {
   <?php if (!empty($name)){ ?>
     $(".p3").show();
   <?php }else{ ?>
     $(".p1").show();
      
   <?php } ?>
});

function fixScroll(){
    let u = navigator.userAgent;
    let isiOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); //ios终端
    if (isiOS) {
      window.scrollTo(0, 0);
    }
 }
$("input, select").blur(function(){
	fixScroll()
});



var _szXuanQu=['上海选区','南通分赛区','其他'];
var _shQu=[
	'杨浦区',
	'金山区',
	'七宝小学联合体',
	'宝山区',
	'嘉定区',
	'徐汇区',
	'普陀区',
	'松江区',
	'浦东新区',
	'奉贤区',
	'崇明区',
	'虹口区',
	'长宁区',
	'闵行区',
	'青浦区',
	'静安区',
	'黄浦区'
];
var _ntQu=[
	'启东市',
	'如东县',
	'如皋市',
	'崇川区',
	'市直代管',
	'开发区代管',
	'海安市',
	'海门市',
	'港闸区',
	'通州区',
	'通州湾江海联动开发示范区'
];
 
$("#p2-nianji").change(function(){
	var _data=$(this).val();
	var _html='<option value="">所在选区</option>';
	$(_szXuanQu).each(function(key,value){
		if(6 == _data && '上海选区' == value){
		}else{
			_html+='<option value="'+value+'">'+value+'</option>';
		}
	});
	$("#p2-szqu").html(_html); 
	 
});
var _szqu='';
$("#p2-szqu").change(function(){
	var _data=$(this).val();
	_szqu=_data;
	var _html='<option value=""></option>';
	if('南通分赛区' == _data){
		$(_ntQu).each(function(key,value){
			var _thisname=value;
			if('海门市' == value){
				_thisname='海门区';
			}
			_html+='<option value="'+value+'">'+_thisname+'</option>';
		});
	}else if('上海选区' == _data){
		$(_shQu).each(function(key,value){
			var _thisname=value;
			if('杨浦区' == value){
				_thisname=value+'分会场';
			}
			if('金山区' == value){
				_thisname=value+'分会场';
			}
			if('七宝小学联合体' == value){
				_thisname=value+'分会场';
			}
			_html+='<option value="'+value+'">'+_thisname+'</option>';
		}); 
	}else{
		_html='<option value="其他">其他</option>';
		$(".p2-s1-2").hide();
        $("#p2-school").hide().html("<option value=''>所在学校</option>");
        $("#p2-school2").show();
	}
	$("#p2-school").html("<option value=''>所在学校</option>");
	$("#p2-fxqu").html(_html); 
});

$("#p2-fxqu").change(function(){
	var _data=$(this).val();
	console.log(_data);
	$(".p2-s1-2, #p2-school").show();
	$("#p2-school2").hide();
	if('其他' == _data){
        $(".p2-s1-2").hide();
        $("#p2-school").hide().html("<option value=''>所在学校</option>");
        $("#p2-school2").show();
		return;
	}
	$.post("api/?c=xue", {d:_data,s:_szqu}, function(data){
		var _html='';
		$(data).each(function(index,ele){
			_html+='<option value="'+ele+'">'+ele+'</option>';
		});
		$("#p2-school").html("");
		$("#p2-school").append(_html);
    }, "json"); 
});

var _fdes='<?php echo $openid; ?>';
$(function(){
	$('.container, .bg, .page').width(sWidth).height(h);
	$('.p1-bg, .rule-t1').width(sWidth).height(_rate*1206);
	$('.thebg, .p-b').width(sWidth).height(_rate*1206);

	$('.p1-t1').height(_rate*152).css({"top":_rate*800});

	$('.p1-bao').width(_rate*382).height(_rate*152).css({"top":0, "left":_rate*170});
	$('.p1-rule').width(_rate*180).height(_rate*152).css({"top":0, "left":_rate*550});

	$('.p3-t1').css({"top":_rate*60});
	$('.p3-t2').width(_rate*486).height(_rate*170).css({"top":_rate*926, "left":_rate*136});

	$('.p3-t3').width(_rate*642).height(_rate*720).css({"top":_rate*198, "left":_rate*54});

	$('.p4-t3').width(_rate*646).height(_rate*720).css({"top":_rate*198, "left":_rate*54});
	$('.p4-b1').width(_rate*549).height(_rate*148).css({"top":_rate*928, "left":_rate*100});
 
	 

	$('.p2-t1').css({"top":0});

	$("#p2-name").width(_rate*372).height(_rate*80).css({"top":_rate*240, "left":_rate*278});
	$("#p2-phone").width(_rate*372).height(_rate*80).css({"top":_rate*338, "left":_rate*278});
	$("#p2-email").width(_rate*372).height(_rate*80).css({"top":_rate*438, "left":_rate*278});
	$("#p2-hao").width(_rate*372).height(_rate*80).css({"top":_rate*540, "left":_rate*278});
	$("#p2-nianji").width(_rate*372).height(_rate*80).css({"top":_rate*638, "left":_rate*278});

    $("#p2-szqu").width(_rate*182).height(_rate*80).css({"top":_rate*736, "left":_rate*278});
    $("#p2-fxqu").width(_rate*182).height(_rate*80).css({"top":_rate*736, "left":_rate*470});
    $(".p2-s1").width(_rate*416).height(_rate*109).css({"top":_rate*808, "left":_rate*262});
    $("#p2-school, #p2-school2").width(_rate*372).height(_rate*80).css({"top":_rate*824, "left":_rate*278});
    
	
	$(".p2-jin").width(_rate*470).height(_rate*110).css({"top":_rate*960, "left":_rate*142});
     
	 
 
	$('.p1-click').click(function(){
		$(".weui-msg").html("活动已结束");
        $("#iosDialog2").show();
        return;
		$(".p1").hide();
		if(1 == _hasU){
			$(".p3").fadeIn();
		}else{
			$(".p2").fadeIn();
		}
	});
    
	$(".p2-jin").click(function(){
		 var _name=$("#p2-name").val();
		 var _phone=$("#p2-phone").val();
		 var _email=$("#p2-email").val();
		 var _hao=$("#p2-hao").val();
		 var _nianji=$("#p2-nianji").val();
		 var _szqu=$("#p2-szqu").val();
		 var _fxqu=$("#p2-fxqu").val();
		 var _school=$("#p2-school").val();
		 var _school2=$("#p2-school2").val();

		 if('' == _name){
             $(".weui-msg").html("请填写姓名");
             $("#iosDialog2").show();
             return;
         }
		 if('' == _phone){
             $(".weui-msg").html("请填写手机号");
             $("#iosDialog2").show();
             return;
         }
		 if(false == checkTel(_phone)){
	 			$(".weui-msg").html("请填写正确的手机号");
	            $("#iosDialog2").show();
	            return;
	     }
		 if('' == _email){
             $(".weui-msg").html("请填写电子邮箱");
             $("#iosDialog2").show();
             return;
         }
         var reg=/\@/g;
	 	 var _emailS=_email.substr(0,1);
	 	 var _emailE=_email.substr(-1); 
	 	 if(!reg.test(_email) || '@' == _emailS || '@' == _emailE || _email.indexOf(".") == -1 ){
	 		 $(".weui-msg").html("请填写正确电子邮箱");
             $("#iosDialog2").show();
             return; 
	 	 }
	 	if('' == _hao){
            $(".weui-msg").html("请填写本人学号");
            $("#iosDialog2").show();
            return;
        }
    	 if('' == _nianji){
            $(".weui-msg").html("请选择年级");
            $("#iosDialog2").show();
            return;
         }
    	 if('' == _szqu){
             $(".weui-msg").html("请选择所在选区");
             $("#iosDialog2").show();
             return;
         }
    	 if('' == _fxqu){
             $(".weui-msg").html("请选择分会场");
             $("#iosDialog2").show();
             return;
         }
		 if('' == _school && '其他' != _fxqu){
             $(".weui-msg").html("请选择学校");
             $("#iosDialog2").show();
             return;
         }
		 if('' == _school2 && '其他' == _fxqu){
             $(".weui-msg").html("请输入学校");
             $("#iosDialog2").show();
             return;
         }
         
         $.post("api/?c=bao", {fdes:_fdes,name:_name, phone:_phone
        	 , email:_email, hao:_hao, nianji:_nianji, szqu:_szqu
        	 , fxqu:_fxqu, school:_school, school2:_school2
             }, function(data){
		      console.log(data);
		      if('ok' == data.s){
                  $(".p2").fadeOut();
                  $(".p3").fadeIn();
			  }else{
				  $(".weui-msg").html("请填写正确的信息");
		          $("#iosDialog2").show();
		          return;
			  }
 	     }, "json"); 
         
	});
	 
	function checkTel(tel){
	    return /^1(3|2|4|5|6|7|8|9)[0-9]\d{8}$/.test(tel)
	}
 
	if(h > _rate*1206){
		   var _cha= h - _rate*1246;
		   if(_cha > 0){
			  $('.p1x').attr("src","<?php echo $urlB; ?>img3/index-x.jpg").height(_rate*1464);
		      $('.kai, .t-wan, .t-rule').css({"top":_cha/2});
		      $('.p1-t1').css({"top":_rate*820});
		      $('.thebg').css({"top":_cha/3});
		    
		   }
      
	}

	function _popMsg(msg){
		$(".weui-msg").html(msg);
        $("#iosDialog2").show();
        return;
    }

	$('.p1-bao').click(function(){
        _popMsg("活动已结束")
        return;
		if(1 == _hasU){
			$(".p1").fadeOut();
			$(".p3").fadeIn();
		}else{
			$(".p1").fadeOut();
			$(".p2").fadeIn();
		}
	});
	$('.p1-rule').click(function(){
		$(".p1").fadeOut();
		$(".p4").fadeIn();
	});
	$('.p4-b1').click(function(){
		$(".p4").fadeOut();
		$(".p1").fadeIn();
	});
     $(".p3-t2").click(function(){
    	 _popMsg("活动已结束")
         return;  
		$.post("api/?c=getci", {fdes:_fdes}, function(data){
            if('k' == data.s){
            	$(".weui-msg").html("您已参与答题");
		        $("#iosDialog2").show();
		        return;
            }else{
            	window.location.href="ti.php";
            }
	     }, "json"); 
		
		
	});
 
	$(".weui-btn").click(function(){
        $("#iosDialog2").hide();
	});

    
	if(!('placeholder' in document.createElement('input')) ){   
	    $('input[placeholder],textarea[placeholder]').each(function(){var that = $(this),text= that.attr('placeholder');   
	      if(that.val()===""){that.val(text).addClass('placeholder');}   
	      that.focus(function(){if(that.val()===text){that.val("").removeClass('placeholder');}})   
	      .blur(function(){if(that.val()===""){that.val(text).addClass('placeholder');}})   
	      .closest('form').submit(function(){   
	        if(that.val() === text){that.val('');}});});   
	 }

	setCookie("eTimec", '', 1);
	function setCookie(cname, cvalue, exdays) {
	    var d = new Date();
	    d.setTime(d.getTime() + (exdays*24*60*60*1000));
	    var expires = "expires="+ d.toUTCString();
	    document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/";
	}

 
});
</script>
</body>
</html>